<template>
  <el-form ref="form" :model="merchant" :rules="rules" label-width="150px">
    <el-form-item label="公司全称" prop="nickName">
      <el-input v-model="merchant.comName" maxlength="30"/>
    </el-form-item>
    <el-form-item label="公司注册号" prop="phonenumber">
      <el-input v-model="merchant.comRegisterNum" maxlength="11"/>
    </el-form-item>
    <el-form-item label="公司许可证号" prop="email">
      <el-input v-model="merchant.licensePermit" maxlength="50"/>
    </el-form-item>
    <el-form-item label="联系人" prop="email">
      <el-input v-model="merchant.functionary" maxlength="50"/>
    </el-form-item>

    <el-form-item>
      <el-button type="primary" size="mini" @click="submit">保存</el-button>
      <el-button type="danger" size="mini" @click="close">关闭</el-button>
    </el-form-item>
  </el-form>
</template>

<script>

  import {updataMerchan} from "@/api/payOrder/payOrder";

  export default {

    props: {
      merchant: {
        type: Object
      }
    },

    data() {
      return {

        rules: {
          comName: [
            {required: true, message: "公司全称不能为空", trigger: "blur"}
          ],
          comRegisterNum: [
            {required: true, message: "公司注册号不能为空", trigger: "blur"}
          ],
          licensePermit: [
            {required: true, message: "公司许可证号不能为空", trigger: "blur"}
          ],
          functionary: [
            {required: true, message: "联系人不能为空", trigger: "blur"}
          ]
        },
        phonenumber: [
          {required: true, message: "手机号码不能为空", trigger: "blur"},
          {
            pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
            message: "请输入正确的手机号码",
            trigger: "blur"
          }
        ]
      }
    },
    created() {
    },

    methods: {
      submit() {

        var del = ['createBy','createTime','balance','merchantCode','secretKey','status','delFlag']
        for (var i = 0; i < del.length; i++) {
          delete this.merchant[del[i]];
        }
        this.$refs["form"].validate(valid => {
          if (valid) {
            updataMerchan(this.merchant).then(response => {
              this.$modal.msgSuccess("修改成功");
            });
          }
        });
      },
      close() {
        this.$tab.closePage();
      }
    }
  };
</script>
